package com.tuo51.bizgame.doctorcat.controller;


import com.tuo51.bizgame.doctorcat.domain.*;
import com.tuo51.bizgame.doctorcat.vo.PreferEvaluateVO;
import com.tuo51.core.domain.staffs.Staff;
import com.tuo51.core.service.StaffService;
import com.tuo51.foudation.model.ErrorCode;
import com.tuo51.foudation.model.MemVerificationCache;
import com.tuo51.foudation.model.StatusResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

import static com.tuo51.foudation.constant.RequestConstant.TICKET;


@RequestMapping("/papi/bizgame/doctorcat")
@RestController
@Api(value = "/papi/bizgame/doctorcat", tags = "家长服务号 - 运营游戏 - 猫博士")
public class PAPIDoctorCatController {

    @Autowired
    private MemVerificationCache cache;

    @Autowired
    StaffService staffService;

    @RequestMapping(value = "/save_prefer_evaluate", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "保存相关预约信息", notes = "")
    public StatusResponse savePreferEvaluate(HttpServletRequest req,
                                   HttpServletResponse resp,
                                   @RequestHeader(TICKET) String ticket,
                                   PreferEvaluateVO preferEvaluate) {
        //先取此用户基本信息
        String uid = cache.getStaffId(ticket);

        //
        String verifyCode = preferEvaluate.getVerifyCode();
        String mobile = preferEvaluate.getMobile();
        if( (staffService.isTestMobile(verifyCode) && "123456".equals(verifyCode))
                || staffService.checkSmsCode(mobile, verifyCode)){
            staffService.clearSmsCode(mobile);

            Staff staff = cache.getStaff(ticket);

            //更新当前staff 的手机号码
            staffService.updatePhoneNumber(staff, mobile);

            //然后找到当前用户的prefer对象


            return StatusResponse.success();
        }else{
            return StatusResponse.error(ErrorCode.SMS_CODE_ERROR, "短信验证码错误");
        }
    }


    @RequestMapping(value = "/my-pet", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取我的宠物", notes = "")
    public StatusResponse getMyPet(HttpServletRequest req,
                                   HttpServletResponse resp,
                                   @RequestHeader(TICKET) String ticket) {
        //先取此用户基本信息
        String uid = cache.getStaffId(ticket);

        //获取对应对象的tags
        Pet ret = new Pet();
        ret.setPreferEvaluate(new PreferEvaluate());
        return StatusResponse.success(ret);
    }


    @RequestMapping(value = "/tasks_list", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取今日可完成的任务", notes = "混合参数")
    public StatusResponse getTask(HttpServletRequest req,
                                   HttpServletResponse resp,
                                   @RequestHeader(TICKET) String ticket) {
        //先取此用户基本信息
        String uid = cache.getStaffId(ticket);

        //获取对应对象的tags
        List demo = Arrays.asList(new Task());
        return StatusResponse.success(demo);
    }

    @RequestMapping(value = "/bonus_list", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取奖励列表", notes = "混合参数")
    public StatusResponse getBonus(HttpServletRequest req,
                                    HttpServletResponse resp,
                                    @RequestHeader(TICKET) String ticket) {
        //先取此用户基本信息
        String uid = cache.getStaffId(ticket);

        //获取对应对象的tags
        List demo = Arrays.asList(new Bonus());
        return StatusResponse.success(demo);
    }

    @RequestMapping(value = "/receive_bonus", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取奖励列表", notes = "混合参数")
    public StatusResponse receiveBonus(HttpServletRequest req,
                                    HttpServletResponse resp,
                                    @RequestHeader(TICKET) String ticket,
                                       String bonusId) {
        //先取此用户基本信息
        String uid = cache.getStaffId(ticket);

        //获取对应对象的tags
        return StatusResponse.success(new BonusRecord());
    }

    @RequestMapping(value = "/bonus_record", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取奖励记录", notes = "混合参数")
    public StatusResponse getBounusRecord(HttpServletRequest req,
                                    HttpServletResponse resp,
                                    @RequestHeader(TICKET) String ticket) {
        //先取此用户基本信息
        String uid = cache.getStaffId(ticket);

        //获取对应对象的tags
        List demo = Arrays.asList(new Bonus());
        return StatusResponse.success(demo);
    }

    @RequestMapping(value = "/score_records", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取积分列表", notes = "混合参数")
    public StatusResponse getScoreRecords(HttpServletRequest req,
                                          HttpServletResponse resp,
                                          @RequestHeader(TICKET) String ticket) {
        //先取此用户基本信息
        String uid = cache.getStaffId(ticket);

        //获取对应对象的tags
        List demo = Arrays.asList(new Bonus());
        return StatusResponse.success(demo);
    }
}
